package cn.maihe.elg.operation.centers.fuzhou.dto;

import cn.maihe.elg.operation.centers.fuzhou.dto.handler.LstApplyRespDTO;
import cn.maihe.elg.operation.centers.fuzhou.enums.HyMakeRespCodeEnum;
import cn.maihe.elg.operation.model.dto.BaseResp;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

/**
 * @Description 海迈响应baseDTO
 * @Author WJH
 * @Date 2021/07/12
 */
@Getter
@Setter
public class FZBaseRespDTO<D> extends BaseResp {
    /**
     * 是	响应代码  0成功 其他失败
     */
    private String code;
    /**
     * 是	响应信息
     */
    private String message;

    /**
     * 是	响应信息
     */
    private String status;

    /**
     * 规范业务数据：有值则需要加密
     */
    private D data;

    public static FZBaseRespDTO of(HyMakeRespCodeEnum respCodeEnum, String message) {
        FZBaseRespDTO respDTO = new FZBaseRespDTO();
        respDTO.setCode(respCodeEnum.getRespCode());
        respDTO.setMessage((message == null || message.trim().length() == 0) ? respCodeEnum.getRespDesc() : message);

        return respDTO;
    }

    public static <T extends FZBaseRespDTO> T build(HyMakeRespCodeEnum statusEnum, String msg, Class<T> tClass) {
        try {
            T t = tClass.newInstance();
            t.setCode(statusEnum.getRespCode());
            t.setMessage(msg);
            return t;
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("初始化" + tClass.getName() + "异常：" + e.getMessage(), e);
        }
    }

    public static <T extends FZBaseRespDTO> T success(String msg, Class<T> tClass) {
        return build(HyMakeRespCodeEnum.SUCCESS, msg, tClass);
    }

    public static <T extends FZBaseRespDTO> T error(String msg, Class<T> tClass) {
        return build(HyMakeRespCodeEnum.FAILURE, msg, tClass);
    }

    public static FZBaseRespDTO success(String msg) {
        return FZBaseRespDTO.of(HyMakeRespCodeEnum.SUCCESS, msg);
    }

    public static FZBaseRespDTO error(String msg) {
        return FZBaseRespDTO.of(HyMakeRespCodeEnum.FAILURE, msg);
    }


    public static void main(String[] args) {
//        HyMakeBaseRespDTO<LstApplyRespDTO> test = new HyMakeBaseRespDTO<>();
//        test.setCode("test");
//        test.setMessage("test");
//        LstApplyRespDTO lstApplyRespDTO = new LstApplyRespDTO();
//        lstApplyRespDTO.setCode("test");
//        lstApplyRespDTO.setMessage("test");
//        LstApplyRespDTO.BizData data = new LstApplyRespDTO.BizData();
//        data.setInsuranceNo("test");
//        lstApplyRespDTO.setData(data);
//        test.setData(lstApplyRespDTO);
//        System.out.println(JSON.toJSONString(lstApplyRespDTO));
//        System.out.println(JSON.toJSONString(test));

        LstApplyRespDTO resp = FZBaseRespDTO.success("承保完成", LstApplyRespDTO.class);
        LstApplyRespDTO.BizData data = new LstApplyRespDTO.BizData();
        // 承保接口同步返回信息，等待中心投保材料地址推送后，中心获取支付链接时得兴才有介入审核
        data.setInsuranceNo("test");
        data.setPremium("test");
        //费率单位
        data.setRate("test");
        //跳转到该订单上传申请书&反担保协议书 及 支付凭证页面
//        makeAndSaveApplyFile(acceptOrderBO);
        resp.setData(data);
        System.out.println(JSON.toJSONString(resp));
    }


}
